package com.cloudkeeper.leasing.identity.schedule;

import com.cloudkeeper.leasing.identity.domain.VillageCadres;
import com.cloudkeeper.leasing.identity.repository.PeopleStreamRepository;
import com.cloudkeeper.leasing.identity.service.SumPerHourService;
import com.cloudkeeper.leasing.identity.service.VillageCadresService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.regex.Pattern;

@Component
public class ScheduleTask {

    @Autowired
    private SumPerHourService sumPerHourService;
    @Autowired
    private VillageCadresService villageCadresService;
    @Autowired
    private PeopleStreamRepository peopleStreamRepository;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private static Pattern pattern = Pattern.compile("[0-9]*");
    @Scheduled(cron = "0 5 0-23 * * ?" )
    public void calPeopleStream() {
        sumPerHourService.calPeopleStream();
    }

//    /**
//     * 定时更新村书记任职年限
//     */
//    @Scheduled(cron = "0 10 0 1 * ?")
//    public void generatePeopleStream() {
//        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(VillageCadres.class);
//        detachedCriteria.add(Restrictions.eq("cadresType", "SECRETARY"));
//        detachedCriteria.add(Restrictions.eq("hasRetire", "0"));
//        List<VillageCadres> list = villageCadresService.findAll(detachedCriteria);
//        for (VillageCadres v : list){
//            if (isNumeric(v.getOnDutyMonth())){
//                if (Integer.valueOf(v.getOnDutyMonth()) > 11){
//                }
//            }
//        }
//    }
    public static boolean isNumeric(String str){
        if (StringUtils.isEmpty(str.trim())){
            return false;
        }
        return pattern.matcher(str.trim()).matches();
    }
}
